#ifndef _NMEA_H_
#define _NMEA_H_

#include <inttypes.h>
#include "navigationData.h"
#include "dataIO.h"

// Does cpp have inner classes?
class NMEAData {
public:
	uint32_t itod; // Time of day in millis
	uint32_t groundSpeed; // in 0.1 km/h
	uint32_t heading; // in 0.1 deg
	uint32_t time;
	int32_t lat; // 1e-7
	int32_t lon; // 1e-7
	int32_t alt;
	bool OK;
	uint8_t fixMode;
	uint8_t numberOfSatellites;
	uint32_t horizontalAccuracy;
	NavigationData::DataStatus status;
};

class NMEA_GPS {
private:
	DataInput* dataInput;
	enum ParserState {
		STATE_IDLE, STATE_READ_ID, STATE_DATA, STATE_CHECKSUM1, STATE_CHECKSUM2
	};

	enum Sentence{
		GPVTG, GPGGA, GPRMC
	};

	char id[5];

	uint8_t dataindex;
	uint8_t commaindex;
	ParserState state;
	NMEAData nmeaData;
	Sentence sentence;
	uint8_t checksum;

	void parseGPVTG(char c);
	void parseGPGGA(char c);
	void parseGPRMC(char c);
	void parse(char c);
	void convertResult();

public:
	NMEA_GPS(DataInput* input);
	// Parses until a result is made or until buffer runs empty. May be slow.
	NavigationData::DataStatus task();
};

#endif // _NMEA_H_
